<?php
namespace Open\Pages;
/**
 * Description of Page
 *
 * @author nofear
 */
class Contacts extends Page {
    
    public function index($key) {
        $this->view = new \System\Template('@open\contacts.twig');
        
        $Page       = $this->getCurrentPage($key);
        $repository = $this->EntityManager->getRepository('Shared\Main\SiteObject');

        $this->view->Page         = $Page;
        $this->view->galleryItems = $repository->getAllPictures($Page);
    }
    
    public function submitOffer() {
        $request = $this->getRequest();
        
        $email   = $this->sanitize($request->get('email'), $type = 'email');
        $price   = $this->sanitize($request->get('price'));
        $comment = $this->sanitize($request->get('comment'));
        
        if ($email && $price) {
            $Offer = new \Shared\Main\Offer();
            
            $Offer->setDomain($this->getCurrentDomain());
            $Offer->setEmail($email);
            $Offer->setPrice($price);
            $Offer->setComment($comment);
            
            $Saver = new \Admin\Savers\Saver();
            
            $Saver->process($Offer);
            $Saver->commit();
            
            $message = 'Your offer is send.';
        } else {
            $message = 'Incorrect data!';
        }
        
        $Session = $this->getSession();
        $Session->setMessage($message);
        
        $this->redirect(\Shared\URLManager::getInstance()->createPath('home'));
    }
}
